package com.project.controller;

import com.project.bean.NewsEntity;
import com.project.bean.TianMaoBean;
import com.project.dao.NewsDao;
import com.project.service.ITianMaoService;
import com.project.util.SnowIdUtilss;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("infos")
public class InfosController {
    @Autowired
    NewsDao dao;
    @Autowired
    ITianMaoService service;
    @GetMapping("add")
    public String add (){
        List<TianMaoBean> list = new ArrayList<>();
        list = service.findAll();
        System.out.println(list);
        for(TianMaoBean tianMaoBean: list) {
            NewsEntity infos =new NewsEntity();
            infos.setNewsId(SnowIdUtilss.uniqueLongHex());
            infos.setNewsMovieId(tianMaoBean.getId());
            infos.setNewsImg(tianMaoBean.getImg());
            infos.setNewsName(tianMaoBean.getMovieName());
            infos.setNewsInfo(tianMaoBean.getMovieName()+"这部电影很好看，真的，非常好看");
            dao.save(infos);
            System.out.println(infos);
        }
        return "ok";
    }
    @GetMapping("findAllByInfo/{info}")
    public List<NewsEntity> findAllByInfo(@PathVariable("info") String info){
        List<NewsEntity> list=dao.findAllByNewsInfo(info);
        return list;
    }
}
